package com.collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class NewForDemo {
    public static void main(String[] args) {
        /**
         * 数组
         */
        String[] strings = {"one", "two", "three", "four", "five"};
        /**
         * for循环遍历数组
         */
        for (int i = 0; i < strings.length; i++) {
            System.out.println(strings[i]);
        }

        System.out.println("=========");

        /**
         * 增强for遍历数组
         */
        for (String string : strings) {
            System.out.println(string);
        }

        System.out.println("=========");

        /**
         * 集合
         */
        Collection<String> objects = new ArrayList<>();
        objects.add("one");
        objects.add("two");
        objects.add("three");
        objects.add("four");
        objects.add("five");

        /**
         * 增强for遍历集合
         * 此时不可以进行增删元素
         */
        for (String object : objects) {
            System.out.println(object);
        }

        System.out.println("=========");

        /**
         * 迭代器遍历集合
         */
        Iterator<String> iterator = objects.iterator();
        while (iterator.hasNext()) {
            String next = iterator.next();
            System.out.println(next);
        }



    }
}
